package com.hzw.code.extend

import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject

/**
 *
 * @Author:         HuaZhongWei
 * @CreateDate:     2020/4/16 15:12
 *
 * @Description:    请求扩展
 *
 */

/**
 * 键值对转换为JsonRequestBody
 */
fun convertJsonRequestBody(vararg params: Pair<String, Any>): RequestBody = JSONObject().apply {
    params.forEach { pair ->
        put(pair.first, pair.second)
    }
}.toString().toRequestBody("application/json; charset=utf-8".toMediaType())